import React, { Component } from 'react'
import { Link } from 'react-router-dom'
import Header from '../../components/Header/Header'
import {Button,Form, Input, Toast} from 'antd-mobile'
import { bindActionCreators } from 'redux';
import { getUser,actions } from '../../store/modules/login';
import {connect} from 'react-redux'
 
class Login extends Component {
 
  render() {
    let {
      user,
      l:{changeUser,doLogin},
      history:{push}

    }=this.props
    return (
      <div>
        {/* 父传子 */}
       <Header register title='登录'></Header>
     <div>user:{JSON.stringify(user)}</div>
         <Form layout='horizontal'>
          <Form.Item label='用户名' name='username'>
            <Input placeholder='请输入用户名' clearable onChange={(v)=>changeUser('phone',v)}/>
          </Form.Item>
          <Form.Item label='密码' name='password'>
            <Input placeholder='请输入密码' clearable type='password' onChange={(v)=>changeUser('password',v)}/>
          </Form.Item>
        </Form>
      
      <Button color='primary' onClick={()=>doLogin(push)}>登录</Button> 

      {/* <Link to='/Index'>前往首页</Link> */}
      </div>
    )
  }
}

const mapStateToProps = (state) =>{
  return {
    user:getUser(state),
  }
};
const mapDispatchToProps = (dispatch) =>{
  return {
    l:bindActionCreators(actions,dispatch),
  }
};

export default connect(mapStateToProps,mapDispatchToProps)(Login)
